package edu.ycu.aladdin.web.dto;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.springframework.data.annotation.Transient;

import java.util.*;

/**
 * @author <a href="mailto:wangruihuano@gmail.com">王瑞环</a>
 * @since 1.0
 */
@Data
public class User {

    /**
     * 用户id
     */
    private String id;


    /**
     * 注册时间
     */
    private Long registrationTime;

    /**
     * 单点登录时用到
     */
    @Transient
    private String uid;

    /**
     * 第三方信息
     */
    private JSONObject thirdUserInfos = new JSONObject();

    /**
     * 用户置信度,用以计算标注数据评分
     */
    private List<Confidence> confidences = new ArrayList<>();

    /**
     * 用户名称,用以展示
     */
    private String name;

    @Data
    public class Confidence {

        /**
         * 类别
         */
        private String category;

        /**
         * 权重 [0,1]
         */
        private Double weights;
    }

    public User() {
        init();
    }

    private void init() {
        this.id = UUID.randomUUID().toString().replaceAll("-", "");
        this.registrationTime = System.currentTimeMillis();
    }

    public User(ThirdUserInfoObtainable thirdUserInfo){
        this();
        this.thirdUserInfos.put(thirdUserInfo.getClass().getSimpleName(),thirdUserInfo);
    }
}
